/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Core.CoreManager;
import DataAccess.DocGia;
import DataAccess.PhieuMuon;
import DataAccess.TacGia;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author My PC
 */
public class PhieuMuonController extends CoreManager<PhieuMuon> {
    private String[] columnNames = {"Mã phiếu mượn","Mã độc giả","Ngày mượn","Ngày hẹn trả"};
    public PhieuMuonController()
    { super();
    GetAllData("PhieuMuon");
    }
    @Override
    public void SetcolumnNames()
    {
        super.columnNames=columnNames;
    }
    public void showData(JTable table)
    {
        GetAllData("PhieuMuon");
        DefaultTableModel tableModel=new DefaultTableModel(columnNames, 0);
        table.setModel(tableModel);
       // int no=1;
        for(Object o: super.list)
        {
            PhieuMuon tg=(PhieuMuon)o;
            Vector oneRow=new Vector();
            oneRow.add(tg.getPhieuMuonId());
            oneRow.add(tg.getDocGiaId());
            oneRow.add(tg.getNgayMuon());
            oneRow.add(tg.getNgayHenTra());
            tableModel.addRow(oneRow);
          //  System.out.println(tableModel.);
        }
    }
    public PhieuMuon getTacGiaByIndex(int index)
    {
        return (PhieuMuon)list.get(index);
    }
    
      public int GetLastID()
    {
        if(!list.isEmpty())
        return ((PhieuMuon)this.list.get(list.size()-1)).getPhieuMuonId();
        else return 0;
        
    }
      
      
}

